﻿using System;
using System.Windows.Forms;
using System.Diagnostics;

namespace Client
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {   
            Managers.Manager.InitManager();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (Managers.Manager.isCheckUpdate)
                CheckUpdate();
            Application.Run(new Forms.LoginForm());

        }

        static void CheckUpdate()
        {
            var updateFile = Managers.Manager.userPath + @"\update_package.exe";
            var up = new UpdateHelper.SoftUpdate(Application.ExecutablePath, "yystock", updateFile);
            up.UpdateFinish += () =>
            {
                Forms.WaitWin.Show("成功下载更新文件。");
                var p = Process.Start(updateFile);
                if (p != null)
                {
                    Forms.WaitWin.Show("正在更新文件，请稍后。");
                    p.WaitForExit();
                }
                Forms.WaitWin.Close();
            };

            if (up.IsUpdate)
            {
                var msg = "检查到新版本" + up.newVer.ToString();
                if (up.whatNew != "" && up.whatNew!=null)
                    msg += "\r\n更新内容：\r\n" + up.whatNew;
                MessageBox.Show(msg, "更新" + MyConst.StaticString.APPNAME);
                Forms.WaitWin.Show("正在下载更新，请稍后。");
                up.Update();
            }

        }
    }
}
